using FireStarter.Base;
using FireStarterModeller.BO;

namespace FireStarter.CodeGeneration.Generator
{
    public class ForEachExpression : TemplateExpression
    {
        public ForEachExpression(string collectionName)
        {
            CollectionName = collectionName;
        }

        public string CollectionName { get; private set; }

        public TemplateExpression Part { get; set; }

        protected override string GenerateOne(IModelStrategyMapper mapper, IModelElement modelElement)
        {
            string result = "";
            IGenerationStrategy strategy = mapper.GetStrategy(modelElement.GetType());
            foreach (IModelElement subModelElement in strategy.GetCollection(mapper, modelElement, CollectionName))
            {
                result += DELETION_MARKER + Part.Generate(mapper, subModelElement) + DELETION_MARKER;
            }
            return result;
        }
    }
}